package com.ylyq.ylxx.controller;

import com.ylyq.ylxx.constants.AccountConstant;
import com.ylyq.ylxx.context.FilterContextHandler;
import com.ylyq.ylxx.model.ResponseData;
import com.ylyq.ylxx.model.bean.GetGoodsListBean;
import com.ylyq.ylxx.model.bean.GetOrderDetail;
import com.ylyq.ylxx.model.bean.GetOrderList;
import com.ylyq.ylxx.model.bean.ResultPlan;
import com.ylyq.ylxx.model.request.*;
import com.ylyq.ylxx.service.IJinritemaiOauthService;
import com.ylyq.ylxx.service.IJinritemaiService;
import com.ylyq.ylxx.service.IOceaneginePlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @ClassName JinritemaiController
 * @Description TODO
 * @Author xiaweichao
 * @Date 2020/9/16 20:11
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/Jinritemai")
@Api(description = "鲁班的相关接口")
public class JinritemaiController {
    @Autowired
    private IJinritemaiService iJinritemaiService;
    @Autowired
    private IOceaneginePlanService iOceaneginePlanService;

    @PostMapping("/getOrderList")
    @ApiOperation(value = "获取订单列表",response = GetOrderList.class)
    public ResponseData getOrderList(@RequestBody GetOrderListRequest getOrderListRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS,iJinritemaiService.getOrderList(getOrderListRequest));
    }

    @PostMapping("/getOrderDetail")
    @ApiOperation(value = "获取订单详情",response = GetOrderDetail.class)
    public ResponseData getOrderDetail(@RequestBody GetOrderDetailRequest getOrderDetailRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS,iJinritemaiService.getOrderDetail(getOrderDetailRequest));
    }

    @PostMapping("/getGoodsList")
    @ApiOperation(value = "获取鲁班商品列表",response = GetGoodsListBean.class)
    public ResponseData getGoodsList(@RequestBody GetGoodsListRequest getOrderDetailRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS,iJinritemaiService.getGoodsList(getOrderDetailRequest));
    }

    @PostMapping("/generatePlans")
    @ApiOperation(value = "批量生成计划",response = ResultPlan.class)
    public ResponseData generatePlans(@RequestBody GeneratePlansRequest generatePlansLubanRequest) {
        try {
            return iOceaneginePlanService.generatePlans(generatePlansLubanRequest);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseData(ResponseData.Result.FAIL);
        }
//
//    @PostMapping("/generatePlans")
//    @ApiOperation(value = "批量生成计划",response = GetGoodsListBean.class)
//    public ResponseData generatePlans(@RequestBody GeneratePlansLubanRequest generatePlansLubanRequest) {
//        try {
//            return iJinritemaiService.generatePlans(generatePlansLubanRequest);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return new ResponseData(ResponseData.Result.FAIL);
//        }
    }
}
